﻿public class User {
    public int Id;
    public string Name = "Default";
    public List<ChatBox> ChatBoxList = new List<ChatBox>();
    public User(int id, string name) {
        Id = id;
        Name = name;
    }
    public void AddFriend(User o) {
        ChatBoxList.Add(new ChatBox(this, o));
    }
    public ChatBox? GetChatBox(string name) {
        var res = ChatBoxList
            .Where(m => m.DstUser == name)
            .FirstOrDefault();
        return res;
    }
}

public class ChatBox {
    public static int Cnt = 0;
    public int Id;
    public string SrcUser;
    public string DstUser;
    public List<IChatMessage> MessageList;
    public ChatBox(User s, User d) {
        MessageList = new List<IChatMessage>();
        Id = ++Cnt;
        SrcUser = s.Name;
        DstUser = d.Name;
    }
    public void Display() {
        Console.WriteLine("ChatBox\nfrom " + SrcUser + " to " + DstUser);
        Console.WriteLine("-----------------------------------------------------------------");
        foreach (var message in MessageList) {
            message.Display();
            Console.WriteLine();
        }
        Console.WriteLine("-----------------------------------------------------------------");
    }

    public void AddMessage(IChatMessage message) {
        MessageList.Add(message);
    }
}



